import { defineFakeRoute } from "vite-plugin-fake-server/client";
import { faker } from "@faker-js/faker/locale/zh_CN";

export default defineFakeRoute([
  // 商品列表
  {
    url: "/api/goods/list",
    method: "get",
    response: () => {
      return {
        success: true,
        code: 200,
        data: {
          list: Array.from({ length: 4 }).map(() => ({
            id: faker.number.int(),
            name: faker.commerce.productName(),
            description: faker.commerce.productDescription(),
            brand: faker.company.name(),
            main_image: faker.image.url(),
            picUrls: Array.from({ length: 2 }).map(() => faker.image.url()),
            sort: faker.number.int(),
            detail_html: faker.lorem.paragraphs(),
            status: 1,
            category: faker.commerce.department(), // 如"女装"
            tags: ["新品", "热卖", "限时折扣"],
            create_time: faker.date.past(),

            // 销售属性
            basePrice: faker.commerce.price(50, 5000),
            salePrice: faker.commerce.price(30, 3000),
            stock: 11
          })),
          total: 4
        },
        message: "获取商品列表成功"
      };
    }
  },
  {
    url: "/api/goods/detail",
    method: "get",
    response: () => {
      return {
        code: 200,
        data: {
          // 基本属性
          id: faker.number.int(),
          name: faker.commerce.productName(),
          description: faker.commerce.productDescription(),
          brand: faker.company.name(),
          main_image: faker.image.url(),
          picUrls: Array.from({ length: 2 }).map(() => faker.image.url()),
          sort: faker.number.int(),
          detail_html: faker.lorem.paragraphs(),
          status: 1,
          category: faker.commerce.department(), // 如"女装"
          tags: ["新品", "热卖", "限时折扣"],
          create_time: faker.date.past(),

          // 销售属性
          basePrice: faker.commerce.price(50, 5000),
          salePrice: faker.commerce.price(30, 3000),
          stock: 11
        }
      };
    }
  },
  // 添加商品
  {
    url: "/api/goods/add",
    method: "post",
    response: () => {
      return {
        code: 200,
        data: {
          id: faker.number.int()
        },
        message: "添加商品成功"
      };
    }
  },
  // 修改商品
  {
    url: "/api/goods/update",
    method: "post",
    response: () => {
      return {
        code: 200,
        message: "修改商品成功"
      };
    }
  },
  // 删除商品
  {
    url: "/api/goods/delete",
    method: "post",
    response: () => {
      return {
        code: 200,
        message: "删除商品成功"
      };
    }
  }
]);
